package chapter1;

import java.io.InputStream;

public class Request {
	private InputStream is;
	private String uri;
	
	public String getUri() {
		return uri;
	}
	public Request(InputStream is){
		this.is=is;
	}
	public void parse(){
		StringBuffer buffer=new StringBuffer(2048);
		byte[]  cbuffer=new byte[2048];
		int i;
		try {
			i=is.read(cbuffer);
		} catch (Exception e) {
			e.printStackTrace();
			i=-1;
		}
		for(int j=0;j<i;j++){
			buffer.append((char)cbuffer[j]);
		}
		System.out.println(buffer.toString());
		uri=URIParse(buffer.toString());
		System.out.println(uri);
	}
	public String URIParse(String requestString){
		int index1,index2;
		index1=requestString.indexOf(" ");
		if(index1!=-1){
			index2=requestString.indexOf(" ",index1+1);
			if(index2>index1){
				return requestString.substring(index1+1,index2);
			}
		}
		return null;
	}
	
}
